<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<title>初学JAVAScript</title>
	<style type="text/css">
		div {
			width: 150px;
			height: 50px;
			text-align: center;
			line-height: 50px;
			background-color: #808080;
		}
	</style>
	<script>
		/*
		作业一：编写函数输入两个数和操作符并计算
		*/
		var result;

		function fun() {

			var num1 = prompt("请输入第一个数：")

			var num2 = prompt("请输入第二个数：")

			var oper = prompt("请输入运算符：")

			switch (oper) {
				case "+": {
					result = parseFloat(num1) + parseFloat(num2);
					alert("两数运算结果为：" + num1 + oper + num2 + "=" + result)
					break;
				}

				case "-":
					result = parseFloat(num1) - parseFloat(num2);
					alert("两数运算结果为：" + num1 + oper + num2 + "=" + result)
					break;
				case "*":
					result = parseFloat(num1) * parseFloat(num2);
					alert("两数运算结果为：" + num1 + oper + num2 + "=" + result)
					break;
				case "/":
					result = parseFloat(num1) / parseFloat(num2);
					alert("两数运算结果为：" + num1 + oper + num2 + "=" + result)
					break;
			}



		}
		/*
		作业二：
		*/
		var result;

		function fun2() {

			var scoreNumber = prompt("请输入科目数量：")
			if (scoreNumber <= 0) {
				alert("输入科目错误！")
			} else if (scoreNumber > 0) {
				switch (scoreNumber) {
					case "1": {
						var score1 = prompt("请输入第一科成绩：");
						if (score1 < 0) {
							alert("成绩无效！");
						} else if (score1 >= 0) {

							alert(scoreNumber + "门科目的总成绩为：" + score1)
						}
					}
					break;
				case "2": {
					var score1 = prompt("请输入第一科成绩：");
					if (score1 < 0) {
						alert("成绩无效！");
					} else if (score1 > 0) {
						var score2 = prompt("请输入第二科成绩：");
					}
					if (score2 < 0) {
						alert("成绩无效！");
					} else if (score2 > 0) {
						result = parseFloat(score1) + parseFloat(score2);
						alert(scoreNumber + "门科目的总成绩为：" + result)
					}

				}
				break;
				case "3": {
					var score1 = prompt("请输入第一科成绩：");
					if (score1 < 0) {
						alert("成绩无效！");
					} else if (score1 > 0) {
						var score2 = prompt("请输入第二科成绩：");
					}
					if (score2 < 0) {
						alert("成绩无效！");
					} else if (score2 > 0) {
						var score3 = prompt("请输入第三科成绩：");
					}
					if (score3 < 0) {
						alert("成绩无效！");
					} else if (score3 > 0) {
						result = parseFloat(score1) + parseFloat(score2) + parseFloat(score3);
						alert(scoreNumber + "门科目的总成绩为：" + result)
					}
				}
				break;
				case "4": {
					var score1 = prompt("请输入第一科成绩：");
					if (score1 < 0) {
						alert("成绩无效！");
					} else if (score1 > 0) {
						var score2 = prompt("请输入第二科成绩：");
					}
					if (score2 < 0) {
						alert("成绩无效！");
					} else if (score2 > 0) {
						var score3 = prompt("请输入第三科成绩：");
					}
					if (score3 < 0) {
						alert("成绩无效！");
					} else if (score3 > 0) {
						var score4 = prompt("请输入第四科成绩：");
					}
					if (score4 < 0) {
						alert("成绩无效！");
					} else if (score4 > 0) {
						result = parseFloat(score4) + parseFloat(score1) + parseFloat(score2) + parseFloat(score3);
						alert(scoreNumber + "门科目的总成绩为：" + result)
					}
				}
				break;
				case "5": {
					var score1 = prompt("请输入第一科成绩：");
					if (score1 < 0) {
						alert("成绩无效！");
					} else if (score1 > 0) {
						var score2 = prompt("请输入第二科成绩：");
					}
					if (score2 < 0) {
						alert("成绩无效！");
					} else if (score2 > 0) {
						var score3 = prompt("请输入第三科成绩：");
					}
					if (score3 < 0) {
						alert("成绩无效！");
					} else if (score3 > 0) {
						var score4 = prompt("请输入第四科成绩：");
					}
					if (score4 < 0) {
						alert("成绩无效！");
					} else if (score4 > 0) {
						var score5 = prompt("请输入第五科成绩：");
					}
					if (score5 < 0) {
						alert("成绩无效！");
					} else if (score5 > 0) {
						result = parseFloat(score5) + parseFloat(score4) + parseFloat(score1) + parseFloat(score2) +
							parseFloat(score3);
						alert(scoreNumber + "门科目的总成绩为：" + result)
					}

				}
				break;
				}
			}

		}
	</script>
</head>

<body>
	<input type="button" name="btn" value="计算两数运算结果" onclick="fun()" style="color: #DAA520;" />
	<input type="button" name="btn" value="计算总成绩" onclick="fun2()" style="color: #DAA520;" />
</body>

</html>